<!-- /*
*   @Description:
*   @Author:lxy
*   @Date:2023-03-23 10:23
*/ -->
<template>
  <div class="sddsBox">
    <DialogTemplate
      ref="DialogTemplateRef"
      v-bind="dialogData"
      @closeHanler="closeHanler"
    >
      <div slot="outerMain" style="padding: 0px 20px;">
        <el-steps :space="400" :active="active" align-center finish-status="success">
          <el-step
            title="基本信息"
            @click.native="($event) => stepClickHandler(0)"
          ></el-step>
          <el-step
            title="过敏史"
            @click.native="($event) => stepClickHandler(1)"
          ></el-step>
          <el-step
            title="家属信息"
            @click.native="($event) => stepClickHandler(2)"
          ></el-step>
          <el-step
            title="注意事项"
            @click.native="($event) => stepClickHandler(3)"
          ></el-step>
        </el-steps>
        <el-divider></el-divider>
        <div class="fromClass CHAGE_SCROLLBAR">
          <div class="tck_saiwen_from" v-show="active == 0">
            <fistPage ref="fistPage"></fistPage>
          </div>
          <div class="tck_saiwen_from" v-show="active == 1">
            <beIllMessage ref="beIllMessage"></beIllMessage>
          </div>
          <div class="tck_saiwen_from" v-show="active == 2">
            <familyInformation ref="familyInformation"></familyInformation>
          </div>
          <div class="tck_saiwen_from" v-show="active == 3">
            <contraindications ref="contraindications"></contraindications>
          </div>
        </div>
      </div>

      <div slot="outerFooter" v-if="!this.fromDisabled">
        <el-button @click="($event) => buttonClickHandler(0)">取消</el-button>
        <el-button @click="active--" :disabled="active == 0">上一步</el-button>
        <el-button type="primary" @click="($event) => buttonClickHandler(1)" v-show="active<3">下一步</el-button>
        <el-button type="primary" @click="($event) => buttonClickHandler(1)" v-show="active == 3">保存</el-button>
      </div>
      <div slot="outerFooter" v-else>
        <el-button @click="($event) => buttonClickHandler(0)">关闭</el-button>
      </div>
    </DialogTemplate>
  </div>
</template>

<script>

import DialogTemplate from "@/components/DialogTemplate.vue";

import familyInformation from './itemPage/familyInformation.vue'
import contraindications from './itemPage/contraindications.vue'
import fistPage from "./itemPage/fistPage.vue";
import beIllMessage from './itemPage/beIllMessage.vue'
import { dressingByScreening } from "@/components/config/index";
import {addPeopleHttp} from '@/api/oldPeople'
export default {
  components: {
    DialogTemplate,
    
    beIllMessage,
    familyInformation,
    contraindications,
    fistPage
  },
  name: "taskInFoDialog",
  data() {
    return {
      dialogData: {
        title: "默认为测试标题",
        outWidth: "70%",
        destroyOnClose: true,
        top: "40px",
      },
      fromDisabled: true,
      active: 0,
    };
  },
  mounted() {
   
  },

  methods: {
    //开启弹框
    handleOpen(val, titleType) {
      console.log(5343)
      
      console.log(val, titleType);
      //1.打开弹框，并为弹框赋值标题
      this.$refs.DialogTemplateRef?.openDialogOne();
      this.dialogData.title = "产品服务 -- " + titleType;
      //2.打开弹框后 判断里面的数据是否可以编辑
      this.fromDisabled =
        titleType == "编辑" || titleType == "新增" ? false : true;
      //3.关于上传组件里面的判断
      this.$nextTick(() => {
        this.fromDisabled
          ? this.$refs.UploadTemplateREf?.diabledFunction()
          : this.$refs.UploadTemplateREf?.noDabledFunction();
        this.$refs.UploadTemplateREf?.fileListFunction(fileList);
      });
      //3.为页面赋初始值
      if (val)
        this.fromData = dressingByScreening({ ...this.fromData }, { ...val });
    },
    //弹出框关闭的回调
    closeHanler() {
      //清空一下所有数据
      this.active = 0;
    },
    //保存/取消按钮点击事件
    buttonClickHandler(type) {
      if (type == 1) {
        if (this.active == 3) {
          let oneValue =  this.$refs.fistPage.outValue()
          if(!oneValue.zt) return
          let jiashuValue = this.$refs.familyInformation.outFunction()
          if(!jiashuValue.zt) return
          let jinji = this.$refs.beIllMessage.modifyFunction()
          let zhuyi = this.$refs.contraindications.setOutFunction()
          let pram = {
            oneValue:oneValue.data,
            jiashuValue:jiashuValue.data,
            jinji,
            zhuyi
          }
          console.log("pram",pram)
          addPeopleHttp(pram).then(res=>{
            console.log(res)
            if(res.data == '404') {
              this.$notify({title: '提示',message: '添加失败',type: 'warning'});
              return
            }else if(res.data == '405'){
              this.$notify({title: '提示',message: '该身份证信息已经被录入',type: 'warning'});
              return
            }
            this.$notify({title: '提示',message: '添加成功',type: 'success'});
            this.$emit('okShuaxin',{})
            this.$refs.DialogTemplateRef?.closeDialogOne();
          })
           // this.$refs.formRef.validate((vaild) => {
          //   if (vaild) {
          //     console.log("准备保存", this.fromData);
          //   }
          // });
         
         
        }else if (this.active < 3){
          this.active++
        }
      } else if (type == 0) {
        //取消操作
        this.$refs.DialogTemplateRef?.closeDialogOne();
      }
    },
    stepClickHandler(num) {
      console.log("点击了");
      this.active = num;
    },
   
  },
};
</script>

<style scoped lang="less">
.sddsBox{
  overflow: hidden;
}
.public_row {
  width: 75%;
  // background-color: aqua;
}
/deep/.el-form-item {
  margin-bottom: 15px;
}
/deep/.el-dialog__body {
  height: 600px;
  overflow: hidden;
  .fromClass{
    height: 500px;
    overflow: auto;
  }
}

</style>
